
<script type="text/javascript">
$(function(){
    var data = {};
    var vis = $('.visibility');
    $.each(vis,function(i,elm){
        $(elm).change(function(sel){
           data.id = sel.target.id;
           data.value =  sel.target.value;
            $.ajax({
                url:'/admin/site/setvisib',
                dataType:'JSON',
                type:'POST',
                data:data
            });
        });
    });
    $.getJSON('/admin/site/getartdata',function(ob){
        $.each(ob,function(i,art){

            var artspan = $('#article_'+art.article_id).empty().append(art.count || 0);
            var rating = $('#rating_'+art.article_id).empty().append(art.sumscore || 0);
            var comments = $('#comments_'+art.article_id).empty().append(art.comments || 0)
            var score = $("#score_"+art.article_id).attr('data-average',art.sumscore || 0).jRating({rateMax:5,isDisabled:true,type:'small'});

        });
    });
var pages = $('#pages');
    var segment,a;
    pages.css({float:'left',width:'auto',height:'15px','margin-top':'30px'});
    if(pages.attr('data-pagescount') > 1){

        for(var i=1;i <= pages.attr('data-pagescount');i++){

            segment = $('<span>',{class:'pages_current',style:"cursor:pointer;background-color:#7FBDFA;border:1px solid #072A66;font-size:12px;font-weight:bold;margin:3px;padding:3px 5px;text-decoration:none;width:15px;height:20px;"});

            pages.append(segment.text(i).attr('id',i));
        }
    }
    $('.pages_current').click(function(){
       var pagenumber = $(this).attr('id');
        $.ajax({
            url:'/admin/site/pagination/',
            dataType:'JSON',
            data:{'page':pagenumber},
            type:'GET',
            success:function(resp){
                console.log(resp);
            }
        });
    });
});
</script>

<?php if($this->page):?>
<?php foreach($this->page as $p):?>

    <div style="padding:10px;width:900px;word-wrap:break-word;"><img src="/images/articles/<?=$p['img']?>" width="60" style="vertical-align:middle;border-radius:3px;"/><span style="padding:10px;"><?=$p['title']?></span></div>

    <span class="created">Дата создания: <?=$p['created_dt'];?></span> | Опубликован:
    <select class="visibility" id="<?=$p['article_id']?>">
       <option value="<?=$p['visibility']=='yes' ? 'yes':'no'?>"><?=$p['visibility']=='yes' ? 'да':'нет'?></option>
       <option value="<?=$p['visibility']=='yes' ? 'no' : 'yes' ?>"><?=$p['visibility']=='yes' ? 'нет' : 'да' ?></option>
    </select>
    | Число просмотров:<span id="article_<?=$p['article_id']?>">0</span>
    | Всего комментариев:<span id="comments_<?=$p['article_id']?>">0</span>
    | Всего голосов:<span id="count">0</span> |
     Рейтинг:<span id="rating_<?=$p['article_id']?>" style="padding:0 5px;margin:0;">0</span><span id="score_<?=$p['article_id']?>" data-average="" style="float:right;margin:6.5px 30px 0 0;"></span>

    <hr/>
<?php endforeach;?>
<?php endif;?>
<div id="pages" data-pagescount="<?=$this->pages?>" ></div>